home *** CD-ROM | disk | FTP | other *** search
/ Aminet 30 / Aminet 30 (1999)(Schatztruhe)[!][Apr 1999].iso / Aminet / gfx / edit / gcview.lha / GCView / GCView.gc < prev    next >
Text File  |  1999-02-05  |  15KB  |  612 lines

  1. G4C
  2.  
  3. ; ******************** This is a Gui4Cli gui *********************
  4.  
  5. ; - You need Gui4Cli version 3.6+ to run it 
  6. ; - Get it from Aminet or <http://users.hol.gr/~dck/gcmain.htm>
  7.  
  8. ; ****************************************************************
  9.  
  10. ; TAB size is 3
  11.  
  12. ; This gui works fine, but it is still a long way from finished.
  13. ; It does however, make gcview easier to use. Feel free to change it..
  14.  
  15. ; ================================================================
  16.  
  17. WINBIG 5 11 658 95 ''
  18. wintype 00001100
  19. screen GCView
  20. ; resinfo 8 640 256
  21. BOX 0 0 658 95 out button
  22.  
  23. xOnLoad
  24.    Local scheight/winheight/barheight
  25.  
  26.    screentog = 0  ; screen2front toggle
  27.    loadedas = NORMAL
  28.    start  = 0
  29.    frames = 60
  30.    file = ''
  31.    loadall = ON
  32.    andir = PINGPONG
  33.    dmode = BG
  34.  
  35.    fcount = 0
  36.    savepath = T:
  37.    savebase = GCPic
  38.    savename = ''
  39.  
  40.    makescreen GCView 3 'GCView 1.0'
  41.  
  42.    ; start gcview
  43.    ifexists port ~gcview
  44.       extract #this guipath mypath
  45.       joinfile $mypath gcview gcvname
  46.       run $gcvname
  47.       wait port gcview 100
  48.       if $$retcode > 0
  49.          ezreq 'Could not launch GCView!\n' Abort ''
  50.          guiquit #this
  51.       endif
  52.    endif
  53.  
  54.    ; get our screen height
  55.    scheight  = 256
  56.    barheight = 12
  57.    call gcview info pubscreen GCView
  58.    tempvar = $$call.ret
  59.    parsevar tempvar
  60.    if $$parse.total > 3
  61.       scheight  = $$parse.3
  62.       barheight = $$parse.5
  63.    endif
  64.  
  65.    ; open window right below menu bar & get actual height
  66.    ; changegad #this 0 -1 $barheight 0 95 '' ; doesn't work.. ?
  67.    guiopen #this
  68.    info gui #this
  69.    winheight = $$win.h
  70.  
  71.    ; move screen down..
  72.    scpos = $($scheight - $barheight - $winheight)
  73.    call gcview move pubscreen GCView 0 $scpos
  74.    call gcview set pointer on
  75.  
  76.    ; notify keys
  77.    call gcview notify RMB Gui4Cli 'gosub gcview.gc do_rmb'
  78.  
  79. xOnQuit
  80.    guiclose #this
  81.    killscreen GCView
  82.    call gcview quit force
  83.  
  84. xOnRMB
  85.    gosub #this do_rmb
  86.  
  87. xRoutine do_rmb
  88.    if $screentog = 0
  89.       guiscreen gcview.gc back
  90.       screentog = 1
  91.    else
  92.       guiscreen gcview.gc front
  93.       screentog = 0
  94.    endif
  95.  
  96.  
  97. ; -----------------------------------------------------------
  98. ;     crop & tile 
  99. ; -----------------------------------------------------------
  100.  
  101. XICON 242 0 :icn/crop
  102.    call gcview crop mypic
  103.    guiscreen gcview.gc front
  104.  
  105. ; -----------------------------------------------------------
  106. ;  Tile 
  107. ; -----------------------------------------------------------
  108. XICON 243 15 :icn/mtile
  109.     gosub #this tilepic 1
  110.  
  111. XICON 243 30 :icn/tile
  112.     gosub #this tilepic 0
  113.  
  114. xRoutine tilepic mirror  ; if mirror=1 then do mirror tile
  115.    guiwindow #this wait
  116.  
  117.    if $type = ANIM
  118.        if $mirror = 1
  119.           call gcview tile mypic MIRROR
  120.         else
  121.             call gcview tile mypic
  122.         endif
  123.  
  124.     else
  125.        ; if there is a box, get size and crop it..
  126.        call gcview info boxsize mypic
  127.        info = $$call.ret
  128.        parsevar info
  129.        if $$parse.2 > 0
  130.            call gcview crop mypic
  131.        endif
  132.  
  133.       call gcview rename mypic brush
  134.       call gcview create mypic 660 512 8
  135.       call gcview open mypic
  136.       call gcview close brush
  137.       call gcview set palette mypic brush
  138.         if $mirror = 1
  139.           call gcview tile brush mypic MIRROR
  140.         else
  141.           call gcview tile brush mypic
  142.         endif
  143.       call gcview unload brush
  144.     endif
  145.  
  146.    guiwindow #this resume
  147.    guiscreen gcview.gc front
  148.  
  149. ; -----------------------------------------------------------
  150. ;  4 way mirror tile (for making bgnd patterns)
  151. ; -----------------------------------------------------------
  152.  
  153. XICON 243 45 :icn/mirror         ; do 4 way mirror
  154.    local w/d/h/sw/sh
  155.  
  156.    if $type = ANIM
  157.       call gcview beep ; not for anims..
  158.       stop
  159.    endif
  160.  
  161.    ; get sizes
  162.    call gcview info size mypic
  163.    size = $$call.ret
  164.    parsevar size
  165.    w = $$parse.0
  166.    h = $$parse.1
  167.    d = $$parse.2
  168.    sw == $w * 2
  169.    sh == $h * 2
  170.  
  171.    ; prepare background for tiling..
  172.    call gcview rename mypic brush
  173.    call gcview create mypic $sw $sh $d
  174.    call gcview open mypic
  175.    call gcview close brush
  176.    call gcview set palette mypic brush
  177.  
  178.    ; paste & flip & paste...
  179.    call gcview paste brush mypic 0 0
  180.    call gcview flip brush horizontal
  181.    call gcview paste brush mypic $w 0
  182.    call gcview flip brush vertical
  183.    call gcview paste brush mypic $w $h
  184.    call gcview flip brush horizontal
  185.    call gcview paste brush mypic 0 $h
  186.  
  187.    ; finished..
  188.    call gcview unload brush
  189.    guiscreen gcview.gc front
  190.  
  191. ; -----------------------------------------------------------
  192. ;     Flip and rotate buttons
  193. ; -----------------------------------------------------------
  194.  
  195. XICON 273 0 :icn/HFlip
  196.    call gcview flip mypic horizontal
  197.  
  198. XICON 273 15 :icn/VFlip
  199.    call gcview flip mypic vertical
  200.  
  201. XICON 273 30 :icn/RRotate
  202.    call gcview rotate mypic right
  203.  
  204. XICON 273 45 :icn/LRotate
  205.    call gcview rotate mypic left
  206.  
  207.  
  208. ; -----------------------------------------------------------
  209. ;  Main control buttons
  210. ; -----------------------------------------------------------
  211.  
  212. ; ------------ save/load Ram:1
  213.  
  214. CTEXT 560 8 Ram: #screen 8 2 0 0001
  215.  
  216. XICON 600 4 :icn/open
  217.    ifexists file ram:1
  218.       call gcview unload mypic
  219.       call gcview load $file mypic
  220.       call gcview open mypic
  221.       guiscreen gcview.gc front
  222.    endif
  223.  
  224. XICON 627 4 :icn/Save
  225.    call gcview save mypic ram:1
  226.  
  227. ; ------------ normal save
  228.  
  229. XBUTTON 573 21 80 12 'Save'
  230.     local fname
  231.    if $file < ' '
  232.       file = T:GCPic
  233.    endif
  234.  
  235.     ; try to be clever.. Use previously saved file's path
  236.     if $savename > ''
  237.         extract savename path savename
  238.         extract file file fname
  239.         joinfile $savename $fname fname
  240.     else
  241.         fname = $file
  242.     endif
  243.  
  244.    savename = ''
  245.    call gcview move pubscreen GCView 0 15
  246.    ReqFile -1 -1 300 -40 'Save current picture:' SAVE savename #$fname
  247.    call gcview move pubscreen GCView 0 $scpos
  248.    if $savename > ''
  249.         ifexists file $savename
  250.             ezreq 'File already exists:\n- $savename\nOverwite ?' OverWrite|Cancel choice
  251.             if $choice = 0
  252.                 stop ; user cancelled
  253.             endif
  254.         endif
  255.       guiwindow #this wait
  256.       call gcview save mypic '$savename'
  257.       guiwindow #this resume
  258.    endif
  259.  
  260. ; ------------ Clear & quit
  261.  
  262. XBUTTON 573 33 80 12 'Clear'  ; unload all pics and anims (keep palettes)
  263.    call gcview unload #PIC
  264.    call gcview unload #ANIM
  265.  
  266. XBUTTON 573 45 80 12 'Quit'
  267.    guiquit #this
  268.  
  269. ; ----- TEMPORARY - MOVE PIC TO temp DIR
  270.  
  271. ; XBUTTON 573 70 80 12 '2fav->'
  272. ;   action copy $file .dh1:pic/.temp
  273.  
  274. ; -----------------------------------------------------------
  275. ;     The listview
  276. ; -----------------------------------------------------------
  277.  
  278. XLISTVIEW 2 0 210 92 "" file "" 0 DIR
  279.    gadid 1
  280.    gadfont #mono 8 000
  281.  
  282.    gosub gcview.gc gettype
  283.    if $type != NONE
  284.    and $type != ANIM
  285.  
  286.       if $dmode = BG                   ; normal background
  287.          call gcview rename mypic oldpic
  288.          call gcview load $file mypic
  289.          if $$retcode > 0  ; no memory..
  290.             call gcview unload oldpic
  291.             call gcview load $file mypic
  292.             call gcview open mypic
  293.          else
  294.             call gcview open mypic
  295.             call gcview unload oldpic
  296.          endif
  297.          guiscreen gcview.gc front
  298.          if $usepalette = ON
  299.             call gcview set palette mypic mypal
  300.          endif
  301.          bgdir = $$lv.dir
  302.          gosub #this showinfo
  303.       else                             ; paste brush mode
  304.          gosub GCVIEW.GC pastebrush
  305.  
  306.       endif
  307.  
  308.    elseif $type = ANIM
  309.       if $dmode = BG
  310.          bgdir = $$lv.dir
  311.          gosub #this playanim 0        ; 0=load as many frames as posible
  312.          if $usepalette = ON
  313.             call gcview set palette mypic mypal
  314.          endif
  315.          gosub #this showinfo
  316.       else                             ; paste anims onto each other
  317.          gosub GCVIEW.GC pastebrush
  318.       endif
  319.  
  320.    else
  321.       ; use default gui to handle file
  322.       guiload guis:tools/rtn/filepop $file
  323.       gosub #this showinfo
  324.    endif
  325.  
  326.    lvmulti none
  327.    lvmulti on
  328.    lvmulti show   ; refresh lv
  329.  
  330. ; -----------------------------------------------------------
  331. ;  routine to paste brush into edit box
  332. ; -----------------------------------------------------------
  333.  
  334. xroutine pastebrush
  335.    if $file H= 'FORM????ANIM' ; ANIM
  336.       call gcview anload $file brush 0 1000 FORWARD
  337.    else
  338.       call gcview load $file brush
  339.    endif
  340.    ; store dir
  341.    extract file path brushdir
  342.  
  343.    ; get edit box size
  344.    call gcview info boxsize mypic
  345.    info = $$call.ret
  346.    parsevar info
  347.    x = $$parse.0
  348.    y = $$parse.1
  349.    w = $$parse.2
  350.    h = $$parse.3
  351.    if $w <= 0        ; no box
  352.       ezreq 'Please draw Edit Box first\nby click-dragging mouse.\nBrush will be sized and\npositioned accordingly' OK ''
  353.       stop
  354.    endif
  355.  
  356.    ; adjust & paste brush
  357.    call gcview resize brush $w $h
  358.    call gcview paste brush mypic $x $y
  359.    call gcview unload brush
  360.    guiscreen gcview.gc front
  361.  
  362. ; -----------------------------------------------------------
  363. ;     routine to get picture file types
  364. ; -----------------------------------------------------------
  365.  
  366. xRoutine gettype
  367.    readvar $file 0 16 header     ; read the header
  368.    set deeptrans off
  369.    ; add here any other formats you have datatypes for
  370.    type = NONE
  371.    docase $header
  372.       case S= 'FORM????ILBM' ; IFF
  373.       case S= "??????JFIF"   ; JPEG
  374.       case S= "ÿØÿÄ"         ; JPEG
  375.       case S= "GIF"          ; GIF
  376.       case S= "?PNG"         ; PNG
  377.          type = PIC
  378.          break
  379.       case S= 'FORM????ANIM' ; ANIM
  380.          type = ANIM
  381.    endcase
  382.    set deeptrans on
  383.  
  384. ; -----------------------------------------------------------
  385. ;     listview controls
  386. ; -----------------------------------------------------------
  387.  
  388. XBUTTON 216 0 20 15 "P"
  389.    lvuse #this 1
  390.    lvdir parent
  391.    
  392. XBUTTON 216 15 20 15 "R"
  393.    lvuse #this 1
  394.    lvdir root
  395.  
  396. XBUTTON 216 30 20 15 "D"
  397.    lvuse #this 1
  398.    lvdir disks
  399.  
  400. XBUTTON 216 45 20 15 "A"
  401.    lvuse #this 1
  402.    lvmulti all
  403.  
  404. XBUTTON 216 60 20 15 "N"
  405.    lvuse #this 1
  406.    lvmulti none
  407.  
  408. ; ---------------------------------------------------------
  409. ;  status box
  410. ; ---------------------------------------------------------
  411.  
  412. TEXT 309 2 232 13 "" 100 BOX
  413. gadid 10
  414.  
  415. ; -----------------------------------------------------------
  416. ;     anims
  417. ; -----------------------------------------------------------
  418.  
  419. ;* BOX 309 17 231 52 in button
  420.  
  421. XCHECKBOX 373 45 26 11 "LoadAll" loadall "ON" "OFF" ON
  422.    gadid 2
  423.    if $loadall == ON
  424.       setgad #this 3/4 on
  425.    else
  426.       setgad #this 3/4 off
  427.    endif
  428.  
  429. XHSLIDER 354 18 146 11 "Start" start 0 100 0 "%ld"
  430.    gadid 3
  431.    gosub #this checklength
  432.  
  433. XHSLIDER 354 30 146 11 "Long" frames 0 60 60 "%ld"
  434.    gadid 4
  435.    gosub #this checklength
  436.  
  437. xroutine checklength
  438.    remain = $($frtotal - $start)
  439.    if $frames > $remain
  440.       frames = $remain
  441.       update #this 4 $frames
  442.    endif
  443.  
  444. XICON 407 42 :icn/Backward
  445.    if $loadedas = LOADALL
  446.       call gcview set direction mypic backward
  447.    endif
  448.    andir = BACKWARD
  449.  
  450. XICON 438 42 :icn/forward
  451.    call gcview set direction mypic forward
  452.    andir = FORWARD
  453.  
  454. XICON 469 42 :icn/pingpong
  455.    if $loadedas = LOADALL
  456.       call gcview set direction mypic ping
  457.    endif
  458.    andir = PINGPONG
  459.  
  460. XICON 407 57 ":icn/AddFrame"     ; add a frame
  461.    call gcview addframe mypic
  462.    gosub #this showinfo
  463.    ; guiscreen #this front
  464.    ; guiscreen gcview.gc front
  465.  
  466. XICON 438 57 ":icn/DelFrame<"    ; delete frame from end
  467.    call gcview info anim mypic
  468.    info = $$call.ret
  469.    parsevar info
  470.    if $$parse.tot > 1
  471.       call gcview delframe mypic $($$parse.1 - 1) 1
  472.    endif
  473.    gosub #this showinfo
  474.  
  475. XICON 469 57 ":icn/DelFrame>"    ; delete frame from start
  476.    call gcview delframe mypic 0 1
  477.    gosub #this showinfo
  478.  
  479. XICON 373 57 :icn/RRotate        ; reload with new settings
  480.    if $file > ''
  481.       gosub #this playanim 1
  482.       gosub #this showinfo
  483.    endif
  484.  
  485. xRoutine playanim userange       ; play anim - if userange=1, use the
  486.    call gcview unload mypic      ; start/frame values as set
  487.    if $loadall == ON
  488.       loadedas = LOADALL
  489.       if $userange = 1
  490.          call gcview anload $file mypic $start $frames $andir
  491.       else
  492.          call gcview anload $file mypic 0 1000 $andir
  493.       endif
  494.    else
  495.       loadedas = NORMAL
  496.       call gcview load $file mypic
  497.    endif
  498.    call gcview open mypic
  499.    guiscreen gcview.gc front
  500.  
  501. ; -----------------------------------------------------------
  502. ;     update info display
  503. ; -----------------------------------------------------------
  504.  
  505. xroutine showinfo
  506.    local info
  507.    extract file file name
  508.  
  509.    if $type = ANIM
  510.       call gcview info anim mypic
  511.       info = $$call.ret
  512.       parsevar info
  513.       frtotal  = $$parse.0
  514.       frstart  = $$parse.1
  515.       frloaded = $$parse.2
  516.  
  517.       if $frloaded > 0
  518.          update #this 10 '$name ($frtotal\f) LOADED:$frloaded'
  519.       else
  520.          update #this 10 '$name : $frtotal'
  521.       endif
  522.  
  523.       start  = $frstart
  524.       frames = $frloaded
  525.       changearg #this 3 7 $frtotal
  526.       changearg #this 4 7 $frtotal
  527.       update #this 3 $frstart
  528.       update #this 4 $frloaded
  529.  
  530.       redraw #this
  531.       ; use sizes from box
  532.       ; partredraw #this 309 18 234 46
  533.  
  534.    else 
  535.       update #this 10 '$type : $name'
  536.  
  537.    endif
  538.    guiscreen gcview.gc front
  539.  
  540. ; -----------------------------------------------------------
  541. ;     add brushes
  542. ; -----------------------------------------------------------
  543.  
  544. XCYCLER 216 75 107 15 "" dmode
  545.    CSTR "Bgnd"    BG
  546.    CSTR 'Brush'   BR
  547.  
  548.    lvuse #this 1
  549.    if $dmode = BG
  550.       lvdir #$bgdir
  551.    else
  552.       lvdir #$brushdir
  553.    endif
  554.  
  555. ; -----------------------------------------------------------
  556. ;     use palette
  557. ; -----------------------------------------------------------
  558.  
  559. XICON 273 60 :icn/palette
  560.    call gcview move pubscreen GCView 0 0 
  561.    ReqFile -1 -1 300 -40 'Choose a palette' LOAD palname ''
  562.    call gcview move pubscreen GCView 0 160
  563.    ifexists file $palname
  564.       call gcview unload mypal
  565.       call gcview load $palname mypal
  566.    endif
  567.  
  568. XCHECKBOX 303 60 20 15 "" usepalette "ON" "" OFF
  569.    gadid 9
  570.    ifexists file ~$palname
  571.       ezreq 'Please choose a palette!\n' "OK" ""
  572.       update #this 9 0
  573.    endif
  574.  
  575. ; -----------------------------------------------------------
  576. ;  zoom to screen
  577. ;  - if there is an edit box, zoom the contents
  578. ;  - otherwise fit the picture to the screen
  579. ; -----------------------------------------------------------
  580.  
  581. XICON 243 60 :icn/Zoom
  582.    local x/y/w/h
  583.  
  584.    ; get edit box size
  585.    call gcview info boxsize mypic
  586.    info = $$call.ret
  587.    parsevar info
  588.    x = $$parse.0
  589.    y = $$parse.1
  590.    w = $$parse.2
  591.    h = $$parse.3
  592.  
  593.    if $w <= 0                       ; no box - zoom the whole picture
  594.       call gcview info size mypic
  595.       size = $$call.ret
  596.       parsevar size
  597.       w = $$parse.0
  598.       h = $$parse.1
  599.       x = 0
  600.       y = 0
  601.    endif
  602.  
  603.    guiwindow #this wait
  604.    call gcview zoom mypic $x $y $w $h
  605.    guiwindow #this resume
  606.    guiscreen gcview.gc front
  607.  
  608.  
  609.  
  610.  
  611.  
  612.